home *** CD-ROM | disk | FTP | other *** search
- /* Ex 1-18 Write a program to remove trailing blanks & tabs from
- each */
- /* line of input, and to delete entirely blank lines */
-
- /* In order to compile, stack size in linker options was set to
- 3072, with small memory model. */
-
- #include <stdio.h>
- #define MAXLINE 1000 /* maximum input line size */
-
- int getline_n(char line[], int maxline);
- int remove(char tem_line[], char line[], int length);
- /* Line 11 */
-
- main()
- {
- int len; /*current line length */
- char line[MAXLINE]; /* current input line */
- char templine[MAXLINE]; /* temporary line buffer */
-
- while ((len = getline_n(line, MAXLINE)) !=EOF)
- {
- if(len > 0)
- {
- if ((len = remove(templine, line, len)) > 0 ){
- printf("%s", templine); /* Line 21 */
- }
- }
- }
- return 0;
- }
-
- /* getline_n: read a line into s */
-
- /* if line consists of only \n, then return 0; if EOF
- encountered, then return EOF,
- otherwise terminate string with null & return length */
-
- int getline_n(char s[], int lim)
- {
- int c, i;
-
- for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c !=
- '\n'; ++I)
- s[i] = c;
- if (c == EOF)
- return EOF;
- if (c == '\n' && i == 0 )
- {
- return 0;
- }
- if (c == '\n' && i > 0 )
- {
- s[i] = c;
- ++i;
- }
- s[i] = '\0';
- return i;
- }
- /* remove: copy 'line' into 'tem_line'; remove any trailing
- blanks & tabs*/
-
- int remove (char tem_line[], char line[], int length)
- /* Line 54 */
- {
- int i, j, n_trail;
- j = n_trail = 0;
- i = length = 2;
-
- while (i >= 0)
- {
- if (n_trail == 1)
- {
- tem_line[i] + line[i];
- j++;
- if(i==0)
- {
- tem_line[j] = '\n';
- j++;
- tem_line[j] = '\0';
- }
- i==;
- }
- else if (n_trail == 0 )
- {
- if(line[i] == ' '|| line[i] == '\t')
- {
- n_trail = 0;
- i--;
- }
- else
- n_trail = 1;
- }
- else
- ;
- }
- return j;
- }
-
- ex_1-18.c(11) : warning C4028: parameter 1 declaration different
- ex_1-18.c(11) : warning C4031: second parameter list longer than
- the first
- ex_1-18.c(21) : warning C4020: 'remove' : too many actual
- parameters
- ex_1-18.c(54) : warning C4028: parameter 1 declaration different
- ex_1-18.c(54) : warning C4029: declared parameter list different
- from definition
-
-